package statistics.util;

import java.util.List;

import org.hibernate.Session;

import statistics.Reporting;

public class SessionFactoryUtil {
	private Session session;

	public SessionFactoryUtil() {
		session = HibernateUtil.getSessionFactory().getCurrentSession();
	}

	public void beginTransaction() {
		this.session.beginTransaction();
	}

	public void saveTransaction(Reporting reporting) {
		this.session.persist(reporting);
		this.session.save(reporting);
	}

	public void commitTransaction() {
		this.session.getTransaction();
		this.session.flush();
	}

	public void closeSession() {
		HibernateUtil.getSessionFactory().close();
	}
	
	public List listReports() {
		session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List result = session.createQuery("from Reporting").list();
		session.getTransaction().commit();
		return result;
	}
}